import {getCurrentInstance, inject, onMounted, reactive} from 'vue'

export default function(screen) {
  const currentInstance = getCurrentInstance()
  const api = inject('api')

  var data = reactive({
    tableData: [],
    checked: false,
    totalAmount: 0,
    type: ''
  })

  const getListData = () => {
    console.log(screen)
    const a = { ...screen }
    if (data.type == 'time') {
      a.statisticsType = '1'
      // a.dateType = '1'
      if (!a.dateType) {
        a.dateType = '1'
      }
    } else if (data.type == 'product') {
      a.statisticsType = '2'
      a.productSelectType = a.type
    } else if (data.type == 'position') {
      a.statisticsType = '3'
      a.saleAreaType = a.type
    } else if (data.type == 'dep') {
      a.statisticsType = '5'
      a.headType = a.type
    } else if (data.type == 'client') {
      a.statisticsType = '4'
      a.agentSelectType = a.type
    }
    a.amountType = data.checked ? '1' : '2'
    console.log(screen)
    console.log(a)
    data.tableData = []
    data.totalAmount = 0
    api.statistics.STATISTICS_SALE_DETAIL_LIST(a).then(res => {
      if (!res.code) {
        data.tableData = res.data.list.list
        data.totalAmount = res.data.list.totalAmount
      } else {
        currentInstance.proxy.customMessage({ type: 'error', message: res.msg })
      }
    })
  }

  const boxChange = () => {
    getListData()
  }

  onMounted(() => {
    getListData()
  })

  return {
    data,

    getListData,
    boxChange
  }
}

